package cn.yunhe.service.impl;

import cn.yunhe.dao.IRoleDao;
import cn.yunhe.pojo.Permission;
import cn.yunhe.pojo.Role;
import cn.yunhe.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class RoleServiceImpl implements IRoleService {

    @Autowired
    IRoleDao roleDao;

    public List<Role> queryUserRoles(String uid) {
        return roleDao.queryUserRoles(uid);
    }

    public List<Role> queryAll() {
        return roleDao.queryAll();
    }

    public void insertRole(Role role) {
        //维护UUID
        role.setId(UUID.randomUUID().toString().replace("-", ""));
        roleDao.insertRole(role);
    }

    public List<Permission> queryRolePermissions(String roleId) {
        return roleDao.queryRolePermissions(roleId);
    }

    public void insertRolePermissions(String roleId, String[] ids) {
        roleDao.insertRolePermissions(roleId, ids);
    }
}
